﻿#region Using Directives

using System;

#endregion Using Directives


namespace Kongo.Filters
{
    internal static class YesNoFilter
    {
        public static object Handler(object value, string arg)
        {
            // Ensure we have an argument
            if (String.IsNullOrEmpty(arg))
                arg = "yes,no,maybe";

            string[] args = arg.Split(',');
            if (args.Length < 2)
                return value; // Invalid arg

            if (value == null)
                return (args.Length > 2 ? args[2].Trim() : args[1].Trim());
            else if (Helpers.ConvertToBoolean(value))
                return args[0].Trim();
            else
                return args[1].Trim();
        }
    }
}
